package org.example.edusmart.controller;

import org.example.edusmart.utils.AliOSSUtil;
import org.example.edusmart.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@RestController
public class UploadController {

    @Autowired
    private AliOSSUtil aliOSSUtil;

    /**
     * 上传文件到OSS
     * @param image 用户本地文件
     * @return 状态码以及OSS返回的url
     * @throws IOException 用于处理与输入输出操作相关的各种问题
     */
    @PostMapping("/upload")
    public Result upload(MultipartFile image)throws IOException{
        String url = aliOSSUtil.upload(image);//调用阿里云OSS工具类，将上传的文件存入阿里云
        return new Result(url,200,"上传成功");
    }
}
